﻿using Infrastructure.DataAccess;
using Infrastructure.IRepository;
using Microsoft.EntityFrameworkCore;

namespace Infrastructure.Repository
{
    public class UnitOfWork:IUnitOfWork
    {
        private readonly DbContext context;
        public UnitOfWork(DbContext context)
        {
            this.context = context;
        }
        /// <summary>
        /// 持久化更改，返回受影响的行数
        /// </summary>
        /// <returns></returns>
        public async Task<int> SaveChanges()
        {
            return await context.SaveChangesAsync();
        }
        /// <summary>
        /// 获取上下文
        /// </summary>
        /// <returns></returns>
        public DbContext GetDbContext()
        {
            return context;
        }
    }
}